import {
	api
} from '@/config/common.js'
//字母或者符号加数字
export function validatePassword(password) {
	// const regex = /^(?=.*[A-Za-z])(?=.*\d)(?=.*[\W_]).{6,18}$/;
	const regex = /^.{6,20}$/;
	return regex.test(password);
}
 

export function createToken(result) {
	let Base64 = require('js-base64').Base64;
	var header = {
		typ: 'Token',
		alg: "None"
	};
	var payload = {
		name: result.account,
		token: result.sessionToken
	}; 

	var encodeContent = Base64.encodeURI(JSON.stringify(header)) + '.' + Base64.encodeURI(JSON.stringify(
		payload));
	var signature = '';
	var authorization = encodeContent + '.' + signature;
	var sessionToken = 'Bearer ' + authorization;
	return sessionToken;
}

//获取多少年前的时间戳
export function getTimestampYearsAgo(yearsAgo) {
	const date = new Date();
	date.setFullYear(date.getFullYear() - yearsAgo);
	return date.getTime()
}

//获取多少年后的时间戳
export function getTimestampYearsLast(yearsAgo) {
	const date = new Date();
	date.setFullYear(date.getFullYear() + yearsAgo);
	return date.getTime()
}